#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>


void init();
int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep);
void backdoor();

int main(void)
{
	init();
	__try
	{
		char data[0x8];
		_write(1, data, 0x80);
		_read(0, data, 0x80);
		*(char*)0 = '\0';  // trigger SEH
	}
	__except (filter(GetExceptionCode(), GetExceptionInformation()))
	{
		printf("__except called\n");
	}
	printf("entering infinite loop\n");
	while (1);
	return 0;
}

void init()
{
	setvbuf(stdin, NULL, _IONBF, 0);
	setvbuf(stdout, NULL, _IONBF, 0);
	setvbuf(stderr, NULL, _IONBF, 0);
}

int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep)
{
	return code == EXCEPTION_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
}

void backdoor()
{
	system("calc");
	exit(EXIT_SUCCESS);
}